package com.dces.jx.billtest.api.xwManageList;
import com.dces.jx.billtest.dto.xwManageHead.DcBillHeadXwtDto;
import com.dces.jx.billtest.dto.xwManageHead.DcBillHeadXwtParam;
import com.dces.jx.billtest.dto.xwManageList.*;
import com.dces.jx.billtest.common.service.ExcelService;
import com.dces.jx.billtest.common.model.PCodeType;
import com.dces.jx.billtest.dto.xwManageList.DcBillListXwtDto;
import com.dces.jx.billtest.xwManageList.service.DcBillListXwtService;
import com.xdo.pcode.service.PCodeHolder;
import com.xdo.common.token.UserInfoToken;
import com.xdo.domain.PageParam;
import com.xdo.domain.ResultObject;
import com.xdo.springboot.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.net.URLEncoder;
import java.util.List;
/**
 * generated by Generate dc
 * 
 *
 * @author xdoV2.0
 * @date: 2021-9-13
 */
@RestController
@RequestMapping("v1/dcBillListXwt")
@Api(tags = "接口")
public class DcBillListXwtController extends BaseController {
    @Resource
    private DcBillListXwtService dcBillListXwtService;
    @Resource
    private PCodeHolder pCodeHolder;
    @Resource
    private ExcelService excelService;
    @ApiOperation("查询数据汇总信息,根据headID")
    @PostMapping("getDataSummaryByHeadId")
    public ResultObject<DcBillListXwtDto> getDataSummaryByHeadId(@Valid @RequestBody DcBillHeadXwtParam dcBillHeadXwtParam){
        DcBillListXwtDto dc=dcBillListXwtService.getDataSummaryByHeadId(dcBillHeadXwtParam);
        if (dc!=null){
            return ResultObject.createInstance(true,"查询成功",dc);
        }else {
            return ResultObject.createInstance(false,"当前表体无数据");
        }

    }
    @ApiOperation("输入备案序号查询是否备案和返回料件信息")
    @PostMapping("getImgCurrByGNo")
    public ResultObject<EmsCusImgCurDto> getImgCurrByGNo(@Valid @RequestBody EmsCusImgCurParam emsCusImgCurParam){
        EmsCusImgCurDto dc=dcBillListXwtService.getImgCurrByGNo(emsCusImgCurParam);
        return ResultObject.createInstance(true,"查询成功",dc);
    }
    @ApiOperation("输入备案序号查询是否备案和返回成品信息")
    @PostMapping("getExgCurrByGNo")
    public ResultObject<EmsCusExgCurDto> getExgCurrByGNo(@Valid @RequestBody EmsCusImgCurParam emsCusImgCurParam){
        EmsCusExgCurDto dc=dcBillListXwtService.getExgCurrByGNo(emsCusImgCurParam);
        return ResultObject.createInstance(true,"查询成功",dc);
    }
    @ApiOperation("查询输入料号是否备案返回成品信息")
    @PostMapping("getExgCurr")
    public ResultObject<EmsCusExgCurDto> getExgCurr(@Valid @RequestBody EmsCusImgCurParam emsCusImgCurParam){
        EmsCusExgCurDto dc=dcBillListXwtService.getExgCurr(emsCusImgCurParam);
        return ResultObject.createInstance(true,"查询成功",dc);
    }
    @ApiOperation("查询输入料号是否备案返回料件信息")
    @PostMapping("getCopGNoIsNull")
    public ResultObject<EmsCusImgCurDto> getCopGNoIsNull(@Valid @RequestBody EmsCusImgCurParam emsCusImgCurParam){
        EmsCusImgCurDto dc=dcBillListXwtService.getCopGNoIsNull(emsCusImgCurParam);
        return ResultObject.createInstance(true,"查询成功",dc);
    }
    /**
     * @param dcBillListXwtParam
     * @param pageParam
     * @return
     */
    @ApiOperation("分页查询接口")
    @PostMapping("list")
    public ResultObject<List<DcBillListXwtDto>> getListPaged(@RequestBody DcBillListXwtParam dcBillListXwtParam, PageParam pageParam) {
        ResultObject<List<DcBillListXwtDto>> paged = dcBillListXwtService.selectAllPaged(dcBillListXwtParam, pageParam);
        return paged;
    }
    /**
     * @param dcBillListXwtParam
     * @param userInfo
     * @return
     */
    @ApiOperation("新增接口")
    @PostMapping()
    public ResultObject<DcBillListXwtDto> insert(@Valid @RequestBody DcBillListXwtParam dcBillListXwtParam, UserInfoToken userInfo) {

		ResultObject<DcBillListXwtDto> resultObject = ResultObject.createInstance(true, ResultObject.INSERT_SUCCESS);
        DcBillListXwtDto dcBillListXwtDto = dcBillListXwtService.insert(dcBillListXwtParam, userInfo);
        if (dcBillListXwtDto != null) {
            resultObject.setData(dcBillListXwtDto);
        } else {
            resultObject.setSuccess(false);
            resultObject.setMessage(ResultObject.INSERT_FAIL);
        }
        return resultObject;
    }
    /**
     * @param sid
     * @param dcBillListXwtParam
     * @param userInfo
     * @return
     */
    @ApiOperation("修改接口")
    @PutMapping("{sid}")
    public ResultObject<DcBillListXwtDto> update(@PathVariable String sid, @Valid @RequestBody DcBillListXwtParam dcBillListXwtParam, UserInfoToken userInfo) {
        dcBillListXwtParam.setSid(sid);
        DcBillListXwtDto dcBillListXwtDto = dcBillListXwtService.update(dcBillListXwtParam, userInfo);
        ResultObject resultObject = ResultObject.createInstance(true, ResultObject.UPDATE_SUCCESS);
        if (dcBillListXwtDto != null) {
            resultObject.setData(dcBillListXwtDto);
        } else {
            resultObject.setSuccess(false);
            resultObject.setMessage(ResultObject.UPDATE_FAIL);
        }
        return resultObject;
    }
    /**
     * @param sids
     * @return
     */
    @ApiOperation("删除接口")
    @DeleteMapping("{sids}")
    public ResultObject delete(@PathVariable List<String> sids, UserInfoToken userInfo) {
		ResultObject resultObject = ResultObject.createInstance(true, ResultObject.DELETE_SUCCESS);
        dcBillListXwtService.delete(sids, userInfo);
        return resultObject;
    }
    /**
     * @param exportParam
     * @return
     * @throws Exception
     */
    @ApiOperation("Excel数据导出接口")
    @PostMapping(value = "/export")
    public ResponseEntity export(@Valid @RequestBody DcBillListXwtExportParam exportParam, UserInfoToken userInfo) throws Exception{
        List<DcBillListXwtDto> dcBillListXwtDtos = dcBillListXwtService.selectAll(exportParam.getExportColumns());
        dcBillListXwtDtos = convertForPrint(dcBillListXwtDtos);
        return excelService.getExcelHeaders(URLEncoder.encode(exportParam.getName(), "utf-8"), exportParam.getHeader(), dcBillListXwtDtos, userInfo);
    }
    /**
     * 导出pCode转换中文名称
     * @param list
     * @return
     */
    public List<DcBillListXwtDto> convertForPrint(List<DcBillListXwtDto> list) {
        for(DcBillListXwtDto item : list) {
        }
        return list;
    }
}
